//
//  ViewController.m
//  WritingBoard
//
//  Created by Mac mini on 16/1/22.
//  Copyright © 2016年 JuniorCodingPerson. All rights reserved.
//

#import "ViewController.h"

#import "KKWritingBoardView.h"

#import "KKCircleProgressView.h"

#import "KKLoadingButton.h"

@interface ViewController () {
    
    KKWritingBoardView *_writingBoard;
    
    KKCircleProgressView *_circleProgressView;
    
    KKLoadingButton *_loadingButton;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIView *rootView = [self view];
    
    _writingBoard = [[KKWritingBoardView alloc] initWithFrame: [rootView bounds]];
    _writingBoard.backgroundColor = [UIColor whiteColor];
    [rootView addSubview: _writingBoard];
    
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target: _writingBoard action: @selector(reset)];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    _circleProgressView = [[KKCircleProgressView alloc] initWithFrame: CGRectMake(CGRectGetWidth(rootView.bounds)/2 - 50, 100, 100, 100) circleWidth: 10 currentValue: 0 totalValue: 10];
    [rootView addSubview: _circleProgressView];
    
    [self performSelector: @selector(running) withObject: nil afterDelay: 2.0];
    
    
    _loadingButton = [KKLoadingButton buttonWithType: UIButtonTypeCustom];
    _loadingButton.frame = CGRectMake(15, 250, CGRectGetWidth(rootView.bounds) - 30, 50);
    _loadingButton.layer.cornerRadius = 10.0;
    _loadingButton.clipsToBounds = true;
    _loadingButton.backgroundColor = [UIColor orangeColor];
    [_loadingButton setKk_progressTintColor: [UIColor darkGrayColor] trackTintColor: [UIColor lightGrayColor]];
    [rootView addSubview: _loadingButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)running {
    
    static NSInteger index = 0;
    if (index > 100) {
        index = 0;
    }
    index++;
    [_circleProgressView setKk_currentValue: index];
    
    [_loadingButton setProgress: index / 100.0 animated: true];
    
    [self performSelector:_cmd withObject:nil afterDelay: 0.5];
}

@end
